

## The Social Origins of Democracy and Authoritarianism Reconsidered: Prussia and Sweden in Comparison
## by Erik Bengtsson and Felix Kersting
## Comparative Political Studies
## Swedish municipality data set
##
## 1. entering the Bengtsson-Kersting Swedish parish level data

# Set WD
# setwd("")

## the paper's regressions uses Swedish data from three separate sources:
## 1. the excel file "BengtssonKerstingSwedenparishdata.xlsx" which is our base municipality data
## 2. the SND election data, from the excel file "0204 election outcomes 1911-1944.xlsx". See separate R code file
## 3. Sara Moricz's 1892 inequality (voting) data, in the excel file "moriczdata_1892.xlsx". See separate R code file


## 1, 2 and 3 are linked via the municipality name (variable "kommun") 
## so the R codes for 2 and 3 include changes to municipality names to make them matchable.

library(readxl)
library(openxlsx)
library(dplyr)
library(foreign)
library(tidyverse)
library(ggplot2)


## 1 our data
eriksdata<-read_excel("sweden_municipality.xlsx", sheet="data")

## creating new variables from the data. population density
eriksdata$wealthpc1907<-1000*eriksdata$wealth/eriksdata$pop1907
eriksdata$popdens<-eriksdata$pop1900/eriksdata$area
## sectoral employment shares in 1930, based on the Census
eriksdata$agriemplshare1930<-100*(eriksdata$empl1930_agri/eriksdata$empl1930_tot)
eriksdata$indemplshare1930<-100*(eriksdata$empl1930_ind/eriksdata$empl1930_tot)

## THE INEQUALITY VARIABLES
eriksdata$nobleshare<-100*eriksdata$Noble/(eriksdata$Noble+eriksdata$Crown+eriksdata$Tax)
eriksdata$estateshare_1900<-100*(eriksdata$farmown_d+eriksdata$farmten_d)/eriksdata$farmunits_1900
eriksdata$estateshare_1932<-100*eriksdata$sizeclass9/eriksdata$farmunits_1932

## trim the number of decimals to make the dataset more legible
eriksdata[, c("area", "wealthpc1907", "popdens", "agriemplshare1930", "indemplshare1930")] <- 
  round(eriksdata[, c("area", "wealthpc1907", "popdens", 
                      "agriemplshare1930", "indemplshare1930")], 1)
eriksdata[, c("Noble", "Crown", "Tax", "mantal_1900", "nobleshare", "estateshare_1900", "estateshare_1932")] <- 
  round(eriksdata[, c("Noble", "Crown", "Tax", "mantal_1900", "nobleshare", 
                      "estateshare_1900", "estateshare_1932")], 2)
eriksdata[, c("wealth", "pop1805", "pop1865", "pop1880", "pop1900", "pop1907", "emig", "Wealth1830", "empl1930_agri", "empl1930_ind", "empl1930_tot", "w_arable1932", "other_1932", 
              "sizeclass1", "sizeclass2", "sizeclass3", "sizeclass4", "sizeclass5", "sizeclass6", "sizeclass7", "sizeclass8", "sizeclass9", "farmunits_1932")] <- 
  round(eriksdata[, c("wealth", "pop1805", "pop1865", "pop1880", "pop1900", "pop1907", "emig", "Wealth1830", "empl1930_agri", "empl1930_ind", "empl1930_tot", "w_arable1932", "other_1932", 
                      "sizeclass1", "sizeclass2", "sizeclass3", "sizeclass4", "sizeclass5", "sizeclass6", "sizeclass7", "sizeclass8", "sizeclass9", "farmunits_1932")], 0)

## drop urban or semi-urban municipalities. See Appendix B in the paper.
eriksdata <- subset(eriksdata, kommun != "Almby") ## incorporated into Örebro in 1943
eriksdata <- subset(eriksdata, kommun != "Arvika LF") ## incorporated into Arvika in 1944
eriksdata <- subset(eriksdata, kommun != "Avesta") ## in 1919 Avesta kg became town
eriksdata <- subset(eriksdata, kommun != "Björkäng") ## incorporated into Töreboda in 1939
eriksdata <- subset(eriksdata, kommun != "Bollnäs") ## a köping
eriksdata <- subset(eriksdata, kommun != "Borg") ## incorporated into Norrköping in 1936
eriksdata <- subset(eriksdata, kommun != "Bromma-Sthlm") ## incorporated into Stockholm in 1916
eriksdata <- subset(eriksdata, kommun != "Brunn") ## incorporated into Ulricehamn in 1938
eriksdata <- subset(eriksdata, kommun != "Brännkyrka") ## incorporated into Stockholm in 1913
eriksdata <- subset(eriksdata, kommun != "By-Vermland") ## incorporated into Säffle köping in 1943
eriksdata <- subset(eriksdata, kommun != "Båstad") ## became town in 1936
eriksdata <- subset(eriksdata, kommun != "Degerfors-Örebro") ## became town in 1943
eriksdata <- subset(eriksdata, kommun != "Falköping LF") ## special case: western part of Falköping LF was incorporated into Falköping in 1935. dropped for consistency
eriksdata <- subset(eriksdata, kommun != "Fors-Rekarne") ## incorporated in Eskilstuna in 1907
eriksdata <- subset(eriksdata, kommun != "Fosie") ## incorporated in Malmö in 1931
eriksdata <- subset(eriksdata, kommun != "Fässberg") ## became town in 1922, as Mölndal
eriksdata <- subset(eriksdata, kommun != "Hakarp") ## became town in 1919, as Huskvarna
eriksdata <- subset(eriksdata, kommun != "Helsingborg LF") ## incorporated in Helsingborg in 1919
eriksdata <- subset(eriksdata, kommun != "Husie") ## incorporated in Malmö in 1935
eriksdata <- subset(eriksdata, kommun != "Hyllie") ## incorporated into Limhamns köping in 1906 
eriksdata <- subset(eriksdata, kommun != "Högbo") ## incorporated into Sandvikens köping in 1943 
eriksdata <- subset(eriksdata, kommun != "Kalmar LF") ## incorporated in Kalmar in 1925
eriksdata <- subset(eriksdata, kommun != "Karlskoga") ## became town in 1940
eriksdata <- subset(eriksdata, kommun != "Karlstad LF") ## incorporated in Karlstad in 1934
eriksdata <- subset(eriksdata, kommun != "Kumla") ## Successive transformation to town, including Kumla town in 1942.
eriksdata <- subset(eriksdata, kommun != "Lidingö") ## became town in 1926
eriksdata <- subset(eriksdata, kommun != "Ljungby-Kronoberg") ## became town in 1936
eriksdata <- subset(eriksdata, kommun != "Lund LF") ## incorporated in Lund in 1944
eriksdata <- subset(eriksdata, kommun != "Lundby-Gbg") ## incorporated in Gothenburg in 1906
eriksdata <- subset(eriksdata, kommun != "Längbro") ## incorporated in Örebro in 1937
eriksdata <- subset(eriksdata, kommun != "Norra Åsum") ## incorporated in Kristianstad in 1941
eriksdata <- subset(eriksdata, kommun != "Raus") ## incorporated in Helsingborg in 1918
eriksdata <- subset(eriksdata, kommun != "Risinge") ## became town in 1942, as Finspång
eriksdata <- subset(eriksdata, kommun != "Sandseryd") ## became town (köping) in 1943, as Norrhammar
eriksdata <- subset(eriksdata, kommun != "Skara LF") ## incorporated in Skara in 1934
eriksdata <- subset(eriksdata, kommun != "Solna") ## became town in 1943
eriksdata <- subset(eriksdata, kommun != "St Peters kloster") ## incorporated in Lund in 1914
eriksdata <- subset(eriksdata, kommun != "Svedvi") ## became town in 1943, as Hallstahammar
eriksdata <- subset(eriksdata, kommun != "Torpa-Älvsborg") ## incorporated in Borås in 1920
eriksdata <- subset(eriksdata, kommun != "Trollhättan") ## became town in 1916
eriksdata <- subset(eriksdata, kommun != "Vara LF") ## became town (köping) in 1936
eriksdata <- subset(eriksdata, kommun != "Vestanfors") ## became town (Fagersta) in 1944
eriksdata <- subset(eriksdata, kommun != "Vestra Skreflinge") ## incorporated in Malmö in 1911
eriksdata <- subset(eriksdata, kommun != "Visby LF") ## incorporated in Visby in 1936
eriksdata <- subset(eriksdata, kommun != "Vist-Älvsborg") ## incorporated in Ulricehamn in 1938
eriksdata <- subset(eriksdata, kommun != "Växjö LF") ## incorporated in Växjö in 1940
eriksdata <- subset(eriksdata, kommun != "Ånsta") ## incorporated in Örebro in 1943
eriksdata <- subset(eriksdata, kommun != "Örgryte") ## incorporated in Gothenburg in 1922

## drop municipalities which disappear over time -- we want the dataset to be balanced over the 1911 to 1944 period. See Appendix B in the paper.
eriksdata <- subset(eriksdata, kommun != "Arnö")
eriksdata <- subset(eriksdata, kommun != "Dillnäs")
eriksdata <- subset(eriksdata, kommun != "Gåsinge")
eriksdata <- subset(eriksdata, kommun != "Kattunga")
eriksdata <- subset(eriksdata, kommun != "Surteby")
eriksdata <- subset(eriksdata, kommun != "Bro-Vmanland")
eriksdata <- subset(eriksdata, kommun != "Malma-Vmanland")


## EXPORTING THE DATASET
setwd("~/Library/CloudStorage/Dropbox/09 Sonderweg/Replication/temp")
write.xlsx(eriksdata, "parish.xlsx")



## GETTING THE 1911-1944 ELECTION DATA INTO R
## use the R file "SWE 2 importing renaming and merging the SND election data" to load the data and to clean the municipality names so they become matchable


## GETTING THE 1892 INEQUALITY DATA INTO R AND CLEANING IT
## use the R file "SWE 3 importing renaming and merging the Moricz data.R" to load the data and clean the municipality names so they become matchable
